package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class TestNote {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        FileOutputStream fos = new FileOutputStream("fos.txt");
        System.out.println("请输入要输入的文字:");
        while (true){
            String line = scanner.nextLine();
            fos.write(line.getBytes(StandardCharsets.UTF_8));//简洁
//            byte[]data = line.getBytes(StandardCharsets.UTF_8);
//            fos.write(data);
            if("exit".equals(line)){
                System.out.println("程序退出!");
                break;
            }
        }
        fos.close();
        /*
        Scanner scanner  = new Scanner(System.in);
        FileOutputStream fos = new FileOutputStream("note.txt");
        while (true){
            System.out.println("请输入要写的文字:");
            String line = scanner.nextLine();
            byte[]data = line.getBytes(StandardCharsets.UTF_8);
            if ("exit".equals(line)) {//若用户输入的是exit--用equals
                System.out.println("输出完毕,程序退出!");
                break;
            }else {
                fos.write(data);
            }
            fos.close();
        }

         */
    }
}
